﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interpreter.BuiltIns
{
	internal class SystemRandom : Module
	{
		
		public override void Register(FunctionRegistry registry)
		{
			System.Random r = new Random();
			registry.Register(29, new SystemRandomNextInt(r));
			registry.Register(30, new SystemRandomNextFloat(r));
		}

		private class SystemRandomNextFloat : NativeFunction
		{
			private Random r;
			public SystemRandomNextFloat(Random r)
			{
				this.r = r;
			}

			public override Value Do(StackContext stackContext, Value[] args)
			{
				return new Value(Value.TYPE_FLOAT, this.r.NextDouble());
			}
		}

		private class SystemRandomNextInt : NativeFunction
		{
			private Random r;
			public SystemRandomNextInt(Random r)
			{
				this.r = r;
			}

			public override Value Do(StackContext stackContext, Value[] args)
			{
				return Value.GetInteger(this.r.Next());
			}
		}
	}
}
